using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Adex
{
    /// <summary>
    /// Controller class for Brand
    /// </summary>
    [System.ComponentModel.DataObject]
    public partial class BrandController
    {
        // Preload our schema..
        Brand thisSchemaLoad = new Brand();
        private string userName = string.Empty;
        protected string UserName
        {
            get
            {
				if (userName.Length == 0) 
				{
    				if (System.Web.HttpContext.Current != null)
    				{
						userName=System.Web.HttpContext.Current.User.Identity.Name;
					}

					else
					{
						userName=System.Threading.Thread.CurrentPrincipal.Identity.Name;
					}

				}

				return userName;
            }

        }

        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public BrandCollection FetchAll()
        {
            BrandCollection coll = new BrandCollection();
            Query qry = new Query(Brand.Schema);
            coll.LoadAndCloseReader(qry.ExecuteReader());
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public BrandCollection FetchByID(object BrandID)
        {
            BrandCollection coll = new BrandCollection().Where("BrandID", BrandID).Load();
            return coll;
        }

		
		[DataObjectMethod(DataObjectMethodType.Select, false)]
        public BrandCollection FetchByQuery(Query qry)
        {
            BrandCollection coll = new BrandCollection();
            coll.LoadAndCloseReader(qry.ExecuteReader()); 
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public bool Delete(object BrandID)
        {
            return (Brand.Delete(BrandID) == 1);
        }

        [DataObjectMethod(DataObjectMethodType.Delete, false)]
        public bool Destroy(object BrandID)
        {
            return (Brand.Destroy(BrandID) == 1);
        }

        
        
    	
	    /// <summary>
	    /// Inserts a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Insert, true)]
	    public void Insert(int BrandCode,string BrandName,string MediaType,bool Tv,bool Rd,bool Cb,bool Pr,bool Od,bool Ns,DateTime DateAdded,DateTime DateModified,bool InX)
	    {
		    Brand item = new Brand();
		    
            item.BrandCode = BrandCode;
            
            item.BrandName = BrandName;
            
            item.MediaType = MediaType;
            
            item.Tv = Tv;
            
            item.Rd = Rd;
            
            item.Cb = Cb;
            
            item.Pr = Pr;
            
            item.Od = Od;
            
            item.Ns = Ns;
            
            item.DateAdded = DateAdded;
            
            item.DateModified = DateModified;
            
            item.InX = InX;
            
	    
		    item.Save(UserName);
	    }

    	
	    /// <summary>
	    /// Updates a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
	    public void Update(int BrandID,int BrandCode,string BrandName,string MediaType,bool Tv,bool Rd,bool Cb,bool Pr,bool Od,bool Ns,DateTime DateAdded,DateTime DateModified,bool InX)
	    {
		    Brand item = new Brand();
		    
				item.BrandID = BrandID;
				
				item.BrandCode = BrandCode;
				
				item.BrandName = BrandName;
				
				item.MediaType = MediaType;
				
				item.Tv = Tv;
				
				item.Rd = Rd;
				
				item.Cb = Cb;
				
				item.Pr = Pr;
				
				item.Od = Od;
				
				item.Ns = Ns;
				
				item.DateAdded = DateAdded;
				
				item.DateModified = DateModified;
				
				item.InX = InX;
				
		    item.MarkOld();
		    item.Save(UserName);
	    }

    }

}

